package com.hamizhong.iflowers.common.listener;

import java.util.Enumeration;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import com.hamizhong.iflowers.common.logger.MyLogger;
import com.hamizhong.iflowers.common.logger.MyLoggerFactory;

public class IFlowersSessionAttrListener implements HttpSessionAttributeListener {

	Logger logger = LogManager.getLogger(this.getClass());
	
	public void attributeAdded(HttpSessionBindingEvent event) {
		if(logger.isInfoEnabled()) {
			logger.info("----------------------------------------");
			logger.info("Session added, current session keys : ");
			HttpSession session = event.getSession();
			Enumeration e = session.getAttributeNames();
			while(e.hasMoreElements()) {
				logger.info(e.nextElement());
			}
			logger.info("----------------------------------------");
		}
	}

	public void attributeRemoved(HttpSessionBindingEvent event) {
		if(logger.isInfoEnabled()) {
			logger.info("----------------------------------------");
			logger.info("Session destroyed, current session keys : ");
			HttpSession session = event.getSession();
			Enumeration e = session.getAttributeNames();
			while(e.hasMoreElements()) {
				logger.info(e.nextElement());
			}
			logger.info("----------------------------------------");
		}
	}

	public void attributeReplaced(HttpSessionBindingEvent arg0) {

	}

}
